﻿using System;
using System.Runtime.InteropServices;

namespace Vtron.HipcConfigurationTools.Domain
{
    /// <summary>
    /// 版本升级的消息头
    /// </summary>
    /// <remarks>
    /// typedef struct NET_TCP_HEAD_TAG
    /// {
    /// 	UINT uCommandId;  //命令
    /// 	UINT dwDataLen;    //长度
    /// 	char Data[0];  //数据
    /// }NET_TCP_HEAD;
    /// 
    /// uCommandId = 0x4000;  //升级开始
    /// uCommandId = 0x4001;  //开始传输文件
    /// uCommandId = 0x4002;  //传输文件结束
    /// uCommandId = 0x4003;  //升级退出
    /// </remarks>
    [Serializable]
    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct NET_TCP_HEAD_TAG
    {
        public int cmd;//0x4000
        public int fileLen;//16
    }

    [Serializable]
    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct Start
    {
        public NET_TCP_HEAD_TAG head;
        public int fileLen;//大小
        public int checkSum;//校验和
    }

    [Serializable]
    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct Return
    {
        public NET_TCP_HEAD_TAG head;
        public int err;//0没错误
    }

    [Serializable]
    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct Send
    {
        public NET_TCP_HEAD_TAG head;
        public int id;//包序号
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1000)]
        public byte[] data;
    }

//    typedef struct _upgFlash
//{
// upgHead head;
// u32 err;
// u32 operation;
// u32 flashLen;
// u32 fileLen;
//}upgFlash;

    //enum Operation
    //{
    //    Operation_save,
    //    Operation_tar,
    //    Operation_flash,
    //    Operation_done
    //};

    [Serializable]
    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct Over
    {
        public NET_TCP_HEAD_TAG head;
    }
}